Skip to content

Delete Instance.dispose and Instance.reload#25427

Merged
kitlangton merged 1 commit intodevfrom
kit/delete-instance-dispose-reload
May 2, 2026
Merged

Delete Instance.dispose and Instance.reload#25427
kitlangton merged 1 commit intodevfrom
kit/delete-instance-dispose-reload

Conversation

@kitlangton
Copy link
Copy Markdown
Contributor

Summary

Followup to #25424 (which added `InstanceStore.{disposeInstance, reloadInstance}` helpers and left `Instance.dispose` / `Instance.reload` as TODO-marked thin wrappers). Converts the remaining ~12 callers to use the helpers directly, then deletes the wrappers.

Changes

  • Production (1 site): `server/routes/instance/project.ts:84` — `Instance.reload(...)` → `InstanceStore.reloadInstance(...)`
  • Tests (~12 sites): `Instance.dispose()` → `InstanceStore.disposeInstance(Instance.current)`; `Instance.reload(...)` → `InstanceStore.reloadInstance(...)`
  • `test/server/project-init-git.test.ts`: dropped `spyOn(Instance, "reload")` in favor of asserting on the bus event count via a small `disposedEvents()` helper. The bus event is the behavioral signal the test actually cares about; the spy was implementation detail tied to the wrapper. As a side effect this stabilizes a previously flaky test.
  • `src/project/instance.ts`: deleted `dispose` and `reload` methods. Surface is now: `provide`, getters (`current`/`directory`/`worktree`/`project`), `bind`, `restore`.

Tests

  • Targeted suites (instance-state, mcp/lifecycle, permission/next, worktree, question, project-init-git, httpapi-mcp, httpapi-provider): 141/141 pass
  • Full suite: 2336/2337 pass — 1 failure is the pre-existing `session.created` flake on dev, not caused by this change
  • `bun run typecheck` clean

What's left in `Instance`

`Instance.{provide, bind, restore}` + ALS getters. These need the bigger CLI-conversion + ALS-removal work to retire (separate proposals). After that, the `Instance` namespace can be deleted entirely along with `LocalContext.create("instance")`.

Converts the remaining ~12 callers from the legacy Instance.{dispose,reload}
wrappers to the InstanceStore.{disposeInstance,reloadInstance} helpers added
in #25424, then deletes the wrappers. project-init-git.test.ts drops its
spyOn(Instance, 'reload') in favor of asserting on the bus event count
(disposedEvents helper) — the bus event is the actual behavioral signal
the test cares about, the spy was implementation detail.

After this:
- src/project/instance.ts has 4 methods (provide, current/directory/worktree/project getters, bind, restore)
- The spy-induced flake on project-init-git tests goes away (verified locally)

Tests: 2336/2337 pass (the 1 failure is the pre-existing session.created flake on dev).
import { resolver } from "hono-openapi"
import { Instance } from "@/project/instance"
import { InstanceStore } from "@/project/instance-store"
import { Project } from "@/project/project"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test comment.

@kitlangton kitlangton merged commit 3b91557 into dev May 2, 2026
14 checks passed
@kitlangton kitlangton deleted the kit/delete-instance-dispose-reload branch May 2, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant